package com.qf.aop;

import com.qf.entity.User;

/**
 * ThreadLocal
 */
public class UserUtil {

    private static ThreadLocal<User> userLocal = new ThreadLocal<>();

    public static User getUser() {
        return userLocal.get();
    }

    public static void setUser(User user) {
        userLocal.set(user);
    }

    public static void remove(){
        userLocal.remove();
    }
    public static void main(String[] args) {
        ThreadLocal<String> threadLocal = new ThreadLocal<>();
        threadLocal.set("小明");

        new Thread(() -> {
//            threadLocal.set("小黑");
            System.out.println("子线程：" + threadLocal.get());
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("主线程：" + threadLocal.get());
    }
}
